package com.yjhb.android.sbz.activity;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.base.mvp.BasePresenter;
import com.just.agentweb.AgentWeb;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2020/9/14 9:30
 */
public class WebViewActivity extends BaseActivity {
    private final String TAG = "WebViewActivity2";

    @BindView(R.id.title_tv)
    TextView title_tv;
    @BindView(R.id.content_fl)
    FrameLayout content_fl;
    @BindView(R.id.title)
    View titleView;


    private AgentWeb agentWeb;
    private String title;
    private String url;
    private boolean isShowTitle = true;

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_web;
    }

    @Override
    protected boolean isImmerse() {
        return true;
    }

    @Override
    protected void initUI() {
        Intent intent = getIntent();
        title = intent.getStringExtra("title");
        url = intent.getStringExtra("url");
        isShowTitle = intent.getBooleanExtra("isShowTitle", true);
        if (!isShowTitle) {
            titleView.setVisibility(View.GONE);
        }
        title_tv.setText(title);

        agentWeb = AgentWeb.with(this)
                .setAgentWebParent(content_fl, new FrameLayout.LayoutParams(-1, -1))
                .useDefaultIndicator(getResources().getColor(R.color.blue_c7f2))//进度条
                .createAgentWeb()
                .ready()
                .go(url);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void regEvent() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (agentWeb != null)
            if (agentWeb.handleKeyEvent(keyCode, event)) {
                return true;
            }
        return super.onKeyDown(keyCode, event);
    }

    @OnClick({R.id.back_iv})
    public void back_iv() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (agentWeb != null)
            agentWeb.destroy();
    }

}
